<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/login.css">
    <link rel="stylesheet" href="css/tool.css">
</head>
<body>


<div class="login_box">
    <div class="title_box">
        <div class="title">CAAE基金申报管理系统</div>
        <!-- <div class="reg">登录</div> -->
    </div>
    <div class="input_box" id="login">

  
        <div class="item_input">
            <input type="text" v-model="phone" placeholder="手机号码">
            <div class="close_icon"></div>
        </div>

        <div class="item_input">
            <input type="text" v-model="authCode" placeholder="验证码" style="width: 320px;">
            <span class=""  @click="getCode" style="cursor: pointer; padding: 4px 8px;color: #5ED2FB;border: 1px solid #5ED2FB;border-radius: 18px;">{{msg}}</span>
        </div>

        <div class="register">
            <a href="./register.html" class="title14" style= 'color:#3386f3; text-decoration : underline; '>没有账号,去注册</a>
        </div>

        <div class="btn" @click="login">登录</div>

        <div style="margin-left: 50px; margin-right: 20px;">
            <p  style="color: red;">1、请申报者本人操作；</p>
            <p  style="color: red;">2、为保证申报流畅，建议使用较新版本的Google Chrome、火狐浏览器、Microsoft Edge等浏览器！</p>
        </div>
        

    </div>
</div>


<script type="text/javascript" src="./js/vue.js"></script>
<script type="text/javascript" src="./js/axios.min.js"></script>
<script type="text/javascript" src="./js/qs.min.js"></script>
<script type="text/javascript" src="./js/config.js"></script>

<script>

    const recapp = new Vue({
    el: "#login",
    data: {
        count: '',
        timer: null,
        msg: "获取验证码",
        // 参数
        phone:"",
        authCode:"",
    },

    methods: {
        // 获取验证码
        getCode() {
            console.log("获取验证码");
            if (this.phone.length == 0){
                alert("请先输入手机号");
                return;
            }
            let paras = {
                "phone":this.phone,
            };
            console.log(paras);
            var that = this;
            let dt = Qs.stringify(paras);
            axios.post(BaseUrl + "client/sendAuthCode", dt)
            .then(function (response) {
                console.log(response);
                if (response.data.code == 200) {
                    alert(response.data.massage);
                    const TIME_COUNT = 60;
                    if (!that.timer) {
                        that.count = TIME_COUNT;
                        that.show = false;
                        that.timer = setInterval(() => {
                            if (that.count > 0 && that.count <= TIME_COUNT) {
                                that.count--;
                                that.msg = "已发送 (" + that.count + "S) ";
                            } else {
                                clearInterval(that.timer);
                                that.timer = null;
                                that.msg = "获取验证码";
                            }
                        }, 1000)
                    }
                }else{
                    alert(response.data.massage);
                }
            })
            .catch(function (error) {
                console.log(error);
            })
        },

        login(){
            console.log("登录");
            if (this.authCode == 0){
                alert("请输入验证码");
                return;
            }
            let paras = {
                "authCode":this.authCode,
                "phone":this.phone,
                "register":"1",
            };
            console.log("登录参数" + paras);
            // var that = this;
            let dt = Qs.stringify(paras);
            axios.post(BaseUrl + "client/login", dt)
            .then(function (response) {
                console.log(response);
                if (response.data.code == 200) {
                    
                    info = response.data.data[0];
                    localStorage.setItem("company",info.company);
                    localStorage.setItem("eMail",info.eMail);
                    localStorage.setItem("loginId",info.id);
                    localStorage.setItem("sex",info.sex);
                    localStorage.setItem("phone",info.phone);
                    localStorage.setItem("membershipNumber",info.membershipNumber);
                    localStorage.setItem("name",info.name);
                    
                    window.location.href = "./index.html";
                }else{
                    alert(response.data.massage);
                }
            })
            .catch(function (error) {
                console.log(error);
                alert("服务器错误");
            })
        },
    },
    created:function(){
        var that = this;
        
    },
});




</script>




</body>
</html>